package com.flashflexpro.flexdirector.adapter.codec {
import com.flashflexpro.flexdirector.adapter.descriptor.DescPropertyAuto;

import mx.automation.IAutomationObject;
import mx.containers.TabNavigator;
import mx.core.mx_internal;

use namespace mx_internal;

public class CodecTab extends CodecAutoObj {


    override public function decode(
            obj:Object,
            value:Object,
            descProperty:DescPropertyAuto,
            relativeParent:IAutomationObject,
            inString:Boolean = false):void {
        if (value == null) {
            obj[ descProperty.name ] = null;
            return;
        }
        var aoc:IAutomationObject = obj as IAutomationObject;
        if (relativeParent != null) {
            aoc = (relativeParent as TabNavigator).getTabBar();
        }

        for (var i:int = 0; i < aoc.numAutomationChildren; i ++) {
            var delegate:IAutomationObject = aoc.getAutomationChildAt(i);
            if (delegate.automationName == value) {
                obj[ descProperty.name ] = delegate;
                return;
            }
        }
    }
}

}